package demo07;

import java.lang.reflect.Method;

/**
 * @author JYH
 * @version 1.0
 * @date 2022/10/27 16:53
 */
public class Test {
    public static void main(String[] args) throws Exception{
        Class<Mouse> mouseClass = Mouse.class;
        //本类中的指定方法
        Method use = mouseClass.getDeclaredMethod("use");
        System.out.println(use);
        //本类中的指定方法
        Method use2 = mouseClass.getDeclaredMethod("use2", Integer.class);
        System.out.println(use2);
        //本类中的所有方法
        Method[] methods = mouseClass.getDeclaredMethods();
        for (Method method : methods) {
            System.out.println(method);
        }
        //本类和父类的public方法
        Method use3 = mouseClass.getMethod("use3");
        System.out.println(use3);
        ////本类和父类的所有public方法
        Method[] methods1 = mouseClass.getMethods();
        for (Method method : methods1) {
            System.out.println(method);
        }

    }
}
class Computer{
    public int age;
    private String kind;
    public void use3(){
        System.out.println("这是父类的use3方法");
    }
}

class Mouse extends Computer {
    private double price;
    public int size;

    public void use(){
        System.out.println("这是use方法");
    }
    private void use2(Integer a){
        System.out.println("这是use2方法");
    }

    @Override
    public String toString() {
        return "Mouse{" +
                "age=" + age +
                ", price=" + price +
                ", size=" + size +
                '}';
    }
}
